/**
 * amis-core v2.4.0
 * Copyright 2018-2022 fex
 */

import { __awaiter, __generator } from 'tslib';
import '../utils/api.js';
import '../utils/ColorScale.js';
import 'react';
import 'lodash/chunk';
import 'amis-formula';
import 'lodash/isPlainObject';
import '../utils/DataSchema.js';
import '../utils/DataScope.js';
import 'moment';
import '../utils/debug.js';
import 'react-dom';
import '../utils/errors.js';
import '../utils/tpl.js';
import { promisify } from '../utils/helper.js';
import 'classnames';
import '../utils/filter.js';
import 'lodash/isObject';
import 'lodash/isString';
import 'lodash/isBoolean';
import 'lodash';
import '../utils/image.js';
import { registerAction, runActions } from './Action.js';
import '../utils/resize-sensor.js';
import '../node_modules/dom-helpers/esm/addEventListener.js';
import '../utils/SimpleMap.js';
import 'lodash/mapValues';
import 'lodash/camelCase';
import 'uncontrollable';
import 'hoist-non-react-statics';
import '../utils/validations.js';
import '../utils/Animation.js';

/**
 * 自定义动作，JS脚本
 *
 * @export
 * @class CustomAction
 * @implements {ActionObject}
 */
var CustomAction = /** @class */ (function () {
    function CustomAction() {
    }
    CustomAction.prototype.run = function (action, renderer, event) {
        var _a, _b;
        return __awaiter(this, void 0, void 0, function () {
            var scriptFunc;
            return __generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        scriptFunc = (_b = (_a = action.args) === null || _a === void 0 ? void 0 : _a.script) !== null && _b !== void 0 ? _b : action.script;
                        if (typeof scriptFunc === 'string') {
                            scriptFunc = promisify(new Function('context', 'doAction', 'event', scriptFunc));
                        }
                        return [4 /*yield*/, (scriptFunc === null || scriptFunc === void 0 ? void 0 : scriptFunc.call(null, renderer, function (action) { return runActions(action, renderer, event); }, event, action))];
                    case 1:
                        _c.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return CustomAction;
}());
registerAction('custom', new CustomAction());

export { CustomAction };
